package org.itzheng.yuezhi.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Title:添加单个item的点击事件<br>
 * Description: <br>
 * <p/>
 * Company: <br>
 *
 * @author ZhengYongdong
 * @email ItZheng@ZoHo.com
 * @date 2016/6/24 0024
 */
public abstract class BaseRecyclerViewAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter {
    OnItemClickListener mOnItemClickListener;

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if (holder == null || holder.itemView == null) {
        } else {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mOnItemClickListener != null) {
                        mOnItemClickListener.OnItemClick(v, position);
                    }
                }
            });
        }
        onBindViewHolder((VH) holder, position, true);
    }

    /**
     * 重新写一个一样的抽象方法让子类去继承,后面加个标识,避免一样的方法
     *
     * @param holder
     * @param position
     * @param isBaseRecyclerViewAdapter
     */
    public abstract void onBindViewHolder(VH holder, final int position, boolean isBaseRecyclerViewAdapter);

    /**
     * 设置item的点击事件
     *
     * @param onItemClickListener
     */
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void OnItemClick(View view, int position);
    }
}
